﻿package com.badibadi.activity;

import com.badibadi.fragment.MyRecordList0Fragment;
import com.badibadi.mytools.TabHostUtils;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 每日一记
 * 
 * @author Administrator
 * 
 */
public class RecordAdayToRememberActivity extends BaseActivity {

	public TabHost mtabhost;
	public RelativeLayout bottom_btn1, bottom_btn2;
	private android.os.Handler handler = new Handler();
	private Bundle bun;
	public MyRecordList0Fragment mList0Fragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.my_record_list);
		init();
		// initFragment();
		LoadingFragment("new");
	}

	public void init() {
		// TODO Auto-generated method stub
		this.findViewById(R.id.my_record_list_bottom_button).setVisibility(
				View.GONE);
		this.findViewById(R.id.my_record_list_return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		this.findViewById(R.id.my_record_record).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						if (!Utils.getUid(RecordAdayToRememberActivity.this)
								.equals("")) {
							Intent intent = new Intent(
									RecordAdayToRememberActivity.this,
									AddingRecordNewActivity.class);
							startActivity(intent);
						} else {
							Toast.makeText(getApplicationContext(), getResources().getString(R.string.l_xb10), 0)
									.show();
						}
					}
				});
		mtabhost = (TabHost) findViewById(R.id.my_record_tabhost);
		// mTabHost1.
		// tabHost=getTabHost();
		mtabhost.setup();// 放在获取地址的后面
		mtabhost.addTab(mtabhost
				.newTabSpec("my_record one")
				.setIndicator(getResources().getString(R.string.Newest),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab1));
		mtabhost.addTab(mtabhost
				.newTabSpec("my_record two")
				.setIndicator(getResources().getString(R.string.Hot),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab2));
		mtabhost.addTab(mtabhost
				.newTabSpec("my_record three")
				.setIndicator(getResources().getString(R.string.VoteRanking),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab3));
		TabHostUtils.SetTabHost(this, mtabhost);
		mtabhost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				// TODO Auto-generated method stub
				switch (mtabhost.getCurrentTab()) {
				case 0:
					LoadingFragment("new");
					break;
				case 1:
					LoadingFragment("hot");
					break;
				case 2:
					LoadingFragment("vote");
					break;
				default:
					LoadingFragment("new");
					break;
				}
			}
		});
		bottom_btn1 = (RelativeLayout) findViewById(R.id.my_record_bottom_btn1);
		bottom_btn2 = (RelativeLayout) findViewById(R.id.my_record_bottom_btn2);
		bottom_btn1.setSelected(true);
	}

	// /**
	// * 初始化fragment
	// */
	// private void initFragment(String type) {
	// // TODO Auto-generated method stub
	// ViewFragmentHolder holder = new ViewFragmentHolder();
	// mList0Fragment = new MyRecordList0Fragment();
	// bun = new Bundle();
	// bun.putString("type", type);
	// mList0Fragment.setArguments(bun);
	// holder.transaction.replace(R.id.my_record_layout, mList0Fragment);
	// holder.transaction.commit();
	// }

	/**
	 * 根据num来读取framgent
	 * 
	 * @param num
	 */
	private void LoadingFragment(String type) {
		ViewFragmentHolder holder = new ViewFragmentHolder();
		mList0Fragment = new MyRecordList0Fragment();
		bun = new Bundle();
		bun.putString("type", type);
		mList0Fragment.setArguments(bun);
		holder.transaction.replace(R.id.my_record_layout, mList0Fragment);
		holder.transaction.commit();
	}

	/**
	 * 底部按钮的点击事件
	 * 
	 * @param view
	 */
	public void OnClick0(View view) {
		if (view.isSelected() != true) {
			view.setSelected(true);
			bottom_btn2.setSelected(false);
		}
	}

	/**
	 * 底部按钮的点击事件
	 * 
	 * @param view
	 */
	public void OnClick1(View view) {
		if (view.isSelected() != true) {
			view.setSelected(true);
			bottom_btn1.setSelected(false);
		}
	}

}
